/****************************************************************************
Copyright (c) 2023 - 2024 Qualcomm Technologies International, Ltd.

FILE NAME
    audio_plugin_mic_source.c
    
DESCRIPTION
    Implementation of getting audio plugin mic source.
*/

#include <stream.h>
#include <source.h>
#include <stdlib.h>
#include <logging.h>

#include "audio_plugin_if.h"
#include "audio_plugin_common.h"

/****************************************************************************
DESCRIPTION
    Get mic source
*/
Source AudioPluginGetMicSource(const audio_mic_params audio_mic, audio_channel channel)
{
    Source mic_source = NULL;
    audio_instance instance = AudioPluginGetMicInstance(audio_mic);

    switch(audio_mic.type)
    {
        case mic_type_analog:
            mic_source = StreamAudioSource(AUDIO_HARDWARE_CODEC, instance, channel);
        break;
        case mic_type_digital:
            mic_source = StreamAudioSource(AUDIO_HARDWARE_DIGITAL_MIC, instance, channel);
        break;
        case mic_type_pcm:
            mic_source = StreamAudioSource(AUDIO_HARDWARE_PCM, instance, channel);
        break;
        default:
            Panic();
        break;
    }
    PanicFalse(mic_source);
    return mic_source;
}
/****************************************************************************
DESCRIPTION
    set mic bias driven mic bias
*/
bool AudioPluginSetMicBiasDrivenBias(unsigned bias_config, bool set)
{
    mic_bias_id id = (bias_config == BIAS_CONFIG_MIC_BIAS_0 ?
                                                        MIC_BIAS_0 :
                                                        MIC_BIAS_1);
    uint16 value = (set ? MIC_BIAS_FORCE_ON : MIC_BIAS_OFF);

    MicbiasConfigure(id, MIC_BIAS_VOLTAGE, AudioPluginGetMicrophoneBiasVoltage(id));

    return MicbiasConfigure(id, MIC_BIAS_ENABLE, value);

}
